//
//  AppLoadingView.m
//  ZZmetro
//
//  Created by 一介布衣 on 2020/6/5.
//  Copyright © 2020 一介布衣. All rights reserved.
//

#import "AppLoadingView.h"


@interface AppLoadingView ()

@property (nonatomic, weak) IBOutlet UIControl *loadControl;
@property (nonatomic, weak) IBOutlet UIImageView *loadImgView;
@property (nonatomic, weak) IBOutlet UILabel *loadLabel;
@property (nonatomic, weak) IBOutlet UIButton *loadBtn;

@end

@implementation AppLoadingView
+ (instancetype)createWithView
{
    AppLoadingView *tmp = [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class]) owner:nil options:nil] lastObject];
    
    [tmp initWithView];
    
    return tmp;
}

- (void)initWithView
{
    self.loadImgView.image = [UIImage imageNamed:@"Images.bundle/load_failed"];
}

- (void)setTipString:(NSString *)tipString
{
    _tipString = tipString;
    
    self.loadLabel.text = tipString;
}

- (void)setIsFailedState:(BOOL)isFailedState
{
    _isFailedState = isFailedState;
    
    self.loadImgView.hidden = !isFailedState;
    self.loadBtn.hidden = !isFailedState;
}

- (void)addReLoadActionWithTarget:(id)target action:(SEL)selector;
{
    if (_isFailedState)
    {
        [self.loadBtn addTarget:target action:selector forControlEvents:UIControlEventTouchUpInside];
    } else
    {
        [self.loadControl addTarget:target action:selector forControlEvents:UIControlEventTouchUpInside];
    }
}

@end
